﻿//成果统计
var option = {};
option.columns = [
          { title: 'ID', field: 'ID' },
          { title: '一级类型', field: 'LX1Name' },
          { title: '二级类型', field: 'LX2Name' },
          { title: '名称', field: 'Name' },
          { title: '完成班组', field: 'FinishGroup' },
          { title: '分数', field: 'Item', formatter: getScore },
          { title: '状态', field: 'Status', formatter: getStatus, width: 60 },
          { title: '创建人', field: 'CRUser', formatter: getName },
          { title: '创建时间', field: 'CRDate' },
          { title: '操作', field: 'ID', formatter: getCZ, width: 120 }
];

function getScore(value, row) {
    var score = '';
    if (value && value.length > 0) {
        var n = 0;
        $(value).each(function (inx, itm) {
            var data = JSON.parse(itm.Result);
            $(data).each(function (i, m) {
                n = n + (m.fs ? m.fs * 1 : 0);
            })
        })
        score = (n / value.length).toFixed(2);
        
    }
    return score;
}
function getStatus(value, row) {
    var status = '';
    if (value == '1') {
        status = '<span style="color:green;">已发布</span>';
    }
    else {
        status = '未发布';
    }
    return status;
}

function getCZ(value, row) {
    var str = '<a onclick="showxx(' + value + ')">查看</a>';
    if (row.Status == '1') {
        str = str + '&nbsp;&nbsp;<a onclick="fb(' + value + ',0)" style="color:red;">取消发布</a>&nbsp;&nbsp;';
    }
    else {
        str = str + '&nbsp;&nbsp;<a onclick="fb(' + value + ',1)">发布</a>';
    }
    return str;
}

function showxx(id) {
    parent.MyDialog.viewform("SPList\\\\CGXX.aspx?ID=" + id + "&r=" + Math.random(),'查看统计结果');
}

function getName(value, row) {
    return ComFunJS.convertuser(value);
}

function fb(id, sts) {
    var stsname = '发布';
    if (sts == '0') { stsname = '取消发布'; }
    parent.MyDialog.confirm('你确认要' + stsname + '此条记录吗?', function () {
        $.get(ComFunJS.getRootPath() + "/Comon/ComAjaxHandler.ashx", { Action: "UpdateCGZT", Status: sts, FormID: id }, function (data) {
            if (data == "success") {
                parent.MyDialog.success(stsname + "成功");
                var piframe = parent.$('iframe:visible')[0];
                piframe.contentWindow.location.reload();
            }
            else {
                parent.MyDialog.warning(stsname+"失败");

            }
        });
    })
}
